#ifndef VISITABLE_H
#define VISITABLE_H
#include "Visitor.h"
template<typename R = void>
class BaseVisitable
{
public:
	typedef R ReturnType;
	virtual ~BaseVisitable(){}
	virtual ReturnType Accept(BaseVisitor&) =0;
protected:
	template <class T>
	static ReturnType AcceptImpl(T& visited, BaseVisitor& guest)
	{
		if (Visitor<T>* p = dynamic_cast<Visitor<T>*>(&guest) )
			return p->Visit(visited);
		return ReturnType();
	}
};

#define DEFINE_VISITABLE() \
	virtual ReturnType Accept(BaseVisitor& guest) \
	{ return AcceptImpl(*this, guest); }

#endif